'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-09-22 17:23:58
LastEditTime: 2025-09-22 17:30:24
'''



class Solution:

    def longestConsecutive(self, nums):

        # 哈希表查找快
        st = set(nums)

        ans = 0

        for x in st:
            
            # 不是起点直接跳过
            if x - 1 in st:
                continue

            y = x + 1

            while y in st:

                y += 1
            
            ans = max(ans, y - x)

        
        return ans




